All files / src/app/collections/[id]/items/new page.tsx

71.42% Statements 5/7
50% Branches 1/2
100% Functions 1/1
71.42% Lines 5/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32                          1x 1x 1x       1x 1x                      
import { getSession } from "@/lib/auth";
import { redirect } from "next/navigation";
import { getDb } from "@/lib/db";
import { requireCollectionAccess } from "@/lib/collection-access";
import { AppLayout } from "@/components/layout";
import { trail } from "@/components/layout/breadcrumb-trails";
import { ItemForm } from "@/features/items/ItemForm";
 
interface AddItemPageProps {
  params: Promise<{ id: string }>;
}
 
export default async function AddItemPage({ params }: AddItemPageProps) {
  const { id } = await params;
  const session = await getSession();
  Iif (!session?.user) {
    redirect("/login");
  }
 
  const db = getDb();
  const collection = await requireCollectionAccess(db, id, session.user.id);
 
  return (
    <AppLayout breadcrumbs={trail.itemNew(collection)}>
      <div className="mx-auto w-full max-w-2xl">
        <h1 className="mb-6 text-2xl text-ink sm:mb-8 sm:text-3xl">Add item</h1>
        <ItemForm collectionId={collection.id} />
      </div>
    </AppLayout>
  );
}